package statistics;

import junit.framework.TestCase;
import numerics.LinearRegression;
import numerics.LinearRegressionIO;
import numerics.WrongFileFormatException;

public class TestLineaRegression extends TestCase {
	static public double MAX_ERROR = 5E-6, xk = 386;

	public void test1CalcR() throws WrongFileFormatException {
		LinearRegression lr1 = new LinearRegression(
				LinearRegressionIO.parseInputFile("testcase1.txt"), xk);
		assertEquals(0.9545, lr1.getR(), .5E-4);
	}

	public void test1CalcTailArea() throws WrongFileFormatException {
		LinearRegression lr1 = new LinearRegression(
				LinearRegressionIO.parseInputFile("testcase1.txt"), xk);
		assertEquals(1.775E-5, lr1.getTailArea(), .5E-8);
	}

	public void test1CalcBetaZero() throws WrongFileFormatException {
		LinearRegression lr1 = new LinearRegression(
				LinearRegressionIO.parseInputFile("testcase1.txt"), xk);
		assertEquals(-22.55, lr1.getBetaZero(), 0.5E-2);
	}

	public void test1CalcBetaOne() throws WrongFileFormatException {
		LinearRegression lr1 = new LinearRegression(
				LinearRegressionIO.parseInputFile("testcase1.txt"), xk);
		assertEquals(1.728, lr1.getBetaOne(), 0.5E-3);
	}
	
	public void test1CalcYk() throws WrongFileFormatException {
		LinearRegression lr1 = new LinearRegression(
				LinearRegressionIO.parseInputFile("testcase1.txt"), xk);
		assertEquals(644.4, lr1.getYk(), 0.5E-1);
	}

	public void test1CalcUPI() throws WrongFileFormatException {
		LinearRegression lr1 = new LinearRegression(
				LinearRegressionIO.parseInputFile("testcase1.txt"), xk);
		assertEquals(874.4, lr1.getUPI(), .5E-1);
	}

	public void test1CalcLPI() throws WrongFileFormatException {
		LinearRegression lr1 = new LinearRegression(
				LinearRegressionIO.parseInputFile("testcase1.txt"), xk);
		assertEquals(414.4, lr1.getLPI(), .5E-1);
	}


	public void test2CalcR() throws WrongFileFormatException {
		LinearRegression lr2 = new LinearRegression(
				LinearRegressionIO.parseInputFile("testcase2.txt"), xk);
		assertEquals(0.9333, lr2.getR(), .5E-4);
	}

	public void test2CalcTailArea() throws WrongFileFormatException {
		LinearRegression lr2 = new LinearRegression(
				LinearRegressionIO.parseInputFile("testcase2.txt"), xk);
		assertEquals(7.982E-5, lr2.getTailArea(), .5E-8);
	}

	public void test2CalcBetaZero() throws WrongFileFormatException {
		LinearRegression lr2 = new LinearRegression(
				LinearRegressionIO.parseInputFile("testcase2.txt"), xk);
		assertEquals(-4.039, lr2.getBetaZero(), 0.5E-3);
	}
	
	public void test2CalcBetaOne() throws WrongFileFormatException {
		LinearRegression lr2 = new LinearRegression(
				LinearRegressionIO.parseInputFile("testcase2.txt"), xk);
		assertEquals(0.1681, lr2.getBetaOne(), 0.5E-4);
	}

	public void test2CalcYk() throws WrongFileFormatException {
		LinearRegression lr2 = new LinearRegression(
				LinearRegressionIO.parseInputFile("testcase2.txt"), xk);
		assertEquals(60.86, lr2.getYk(), .5E-2);
	}

	public void test2CalcUPI2() throws WrongFileFormatException {
		LinearRegression lr2 = new LinearRegression(
				LinearRegressionIO.parseInputFile("testcase2.txt"), xk);
		assertEquals(88.42, lr2.getUPI(), .5E-2);
	}

	public void test2CalcLPI() throws WrongFileFormatException {
		LinearRegression lr2 = new LinearRegression(
				LinearRegressionIO.parseInputFile("testcase2.txt"), xk);
		assertEquals(33.30, lr2.getLPI(), .5E-2);
	}
}
